from whirlwind.db.mongo import Mongo
from tornado.web import authenticated
from whirlwind.view.decorators import route
from HandlerExtension.BasicHandler import BasicHandler
from application.models.user import User

@route('/')
class IndexHandler(BasicHandler):
    def get(self):
        #template context variables go in here
        template_values = {}

        email_cookie = self.get_secure_cookie('email')
        if email_cookie:
            user = User.lookup(email_cookie)
            if user:
                self.session['username'] = user.username
                self.session['email'] = user._id
                self.session['locale'] = user.profile.locale


        if self.session['username']:
            template_values['username'] = self.session['username']
        else:
            template_values['username'] = ''

        self.render_template('/site/index.html',**template_values)
